package user

import (
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"google.golang.org/grpc"
	"net/http"
	__ "srv/proto"
)

func ExamGet(c *gin.Context) {
	// 1.连接
	conn, err := grpc.Dial("127.0.0.1:50051", grpc.WithInsecure())
	if err != nil {
		fmt.Printf("连接异常： %s\n", err)
	}
	defer conn.Close()
	// 2. 实例化gRPC客户端
	client := __.NewUserServiceClient(conn)
	// 3.组装请求参数
	req := new(__.ExamScoreGetRequest)
	// 4. 调用接口
	response, err := client.ExamScoreGet(context.Background(), req)
	if err != nil {
		fmt.Println("响应异常  %s\n", err)
	}
	fmt.Printf("响应结果： %v\n", response.List)
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "展示成功",
		"data":    response.List,
	})
}
